package com.qingzhuge.pay.controller;

import com.github.binarywang.wxpay.exception.WxPayException;
import com.qingzhuge.controller.base.AbstractController;
import com.qingzhuge.core.annotation.security.Anonymous;
import com.qingzhuge.pay.service.ISysPayWxService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;


/**
 * @author : zero.xiao
 * @description :
 * @date :2018/11/15 0015 下午 18:40
 * @modified :
 * @since : 1.0.0
 */
@Api(tags = "A-微信支付回调")
@RestController
@RequestMapping(ISysPayWxService.NOTIFY_URL)
public class ApiPayNotifyWxController extends AbstractController {
    @Resource
    private ISysPayWxService payWxService;


    @ApiOperation(value = "支付回调通知处理")
    @PostMapping(ISysPayWxService.PAY_URL)
    @Anonymous
    public String parseOrderNotifyResult(@RequestBody String xmlData,
                                         @ApiParam("支付配置id")
                                         @PathVariable Long id) throws WxPayException {
        log.debug("支付回调通知处理 pid:{},xml data:{}", id, xmlData);
        return this.payWxService.parseOrderNotifyResult(xmlData, id);
    }

    @ApiOperation(value = "退款回调通知处理")
    @PostMapping(ISysPayWxService.REFUND_URL)
    @Anonymous
    public String parseRefundNotifyResult(@RequestBody String xmlData,
                                          @ApiParam("支付配置id")
                                          @PathVariable Long id) throws WxPayException {
        log.debug("pid:{},xml data:{}", id, xmlData);
        return this.payWxService.parseRefundNotifyResult(xmlData, id);
    }

    @ApiOperation(value = "扫码支付回调通知处理")
    @PostMapping(ISysPayWxService.SCAN_URL)
    @Anonymous
    public String parseScanPayNotifyResult(@RequestBody String xmlData,
                                           @ApiParam("支付配置id")
                                           @PathVariable Long id) throws WxPayException {
        log.debug("pid:{},xml data:{}", id, xmlData);
        return this.payWxService.parseScanPayNotifyResult(xmlData, id);
    }
}

